/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PrincipalMedico.java
 *
 * Created on 27-abr-2011, 16:49:02
 */

package interfaces;

import Controlador.Controlador;
import GestorCitas.Cita;
import GestorCitas.EstadoCita;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import paciente.PacienteView;
import paciente.Interfaces;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import org.jdesktop.application.Action;
import paciente.Interfaz;

/**
 *
 * @author Victor
 */
public class PrincipalPaciente extends javax.swing.JPanel {

    private PacienteView app;
    
    /** Creates new form PrincipalMedico */
    public PrincipalPaciente(PacienteView a) {
        app = a;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton6 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jButton8 = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(640, 480));
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(paciente.PacienteApp.class).getContext().getResourceMap(PrincipalPaciente.class);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.GridLayout(2, 0));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(paciente.PacienteApp.class).getContext().getActionMap(PrincipalPaciente.class, this);
        jButton1.setAction(actionMap.get("verDatos")); // NOI18N
        jButton1.setFont(Interfaz.setFontSize());
        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel1.add(jButton1);

        jButton2.setAction(actionMap.get("cambiarPass")); // NOI18N
        jButton2.setFont(Interfaz.setFontSize());
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel1.add(jButton2);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        jButton3.setAction(actionMap.get("pedirCita")); // NOI18N
        jButton3.setFont(Interfaz.setFontSize());
        jButton3.setIcon(resourceMap.getIcon("jButton3.icon")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setName("jButton3"); // NOI18N
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel2.add(jButton3);

        jButton4.setAction(actionMap.get("consultarCita")); // NOI18N
        jButton4.setFont(Interfaz.setFontSize());
        jButton4.setIcon(resourceMap.getIcon("jButton4.icon")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setName("jButton4"); // NOI18N
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel2.add(jButton4);

        jButton7.setAction(actionMap.get("cancelarCita")); // NOI18N
        jButton7.setFont(Interfaz.setFontSize());
        jButton7.setIcon(resourceMap.getIcon("jButton7.icon")); // NOI18N
        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setName("jButton7"); // NOI18N
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel2.add(jButton7);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel3.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.GridLayout());

        jButton6.setAction(actionMap.get("consultarEntregas")); // NOI18N
        jButton6.setFont(Interfaz.setFontSize());
        jButton6.setIcon(resourceMap.getIcon("jButton6.icon")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton6.setMinimumSize(new java.awt.Dimension(161, 155));
        jButton6.setName("jButton6"); // NOI18N
        jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel3.add(jButton6);

        jButton5.setAction(actionMap.get("consultarRecetas")); // NOI18N
        jButton5.setFont(Interfaz.setFontSize());
        jButton5.setIcon(resourceMap.getIcon("jButton5.icon")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setToolTipText(resourceMap.getString("jButton5.toolTipText")); // NOI18N
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setName("jButton5"); // NOI18N
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel3.add(jButton5);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel4.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new java.awt.GridLayout());

        jButton8.setAction(actionMap.get("verHistorial")); // NOI18N
        jButton8.setFont(Interfaz.setFontSize());
        jButton8.setIcon(resourceMap.getIcon("jButton8.icon")); // NOI18N
        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setToolTipText(resourceMap.getString("jButton8.toolTipText")); // NOI18N
        jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton8.setName("jButton8"); // NOI18N
        jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton8);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE))))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
     
    }//GEN-LAST:event_jButton8ActionPerformed

    @Action
    public void verHistorial() throws SQLException, IOException, ClassNotFoundException, NoSuchAlgorithmException, ParseException {
        app.abrirHistorialPaciente();
    }
    @Action
    public void verDatos() throws SQLException, IOException, ClassNotFoundException {
        app.abrirVerDatos(Controlador.getUsuarioActivo());
    }

    @Action
    public void cambiarPass() {
        app.abrirCambiarPass();
    }

    @Action
    public void pedirCita() throws NoSuchAlgorithmException, IOException, ClassNotFoundException {
        Cita [] c = Controlador.consultarCitas(Controlador.getUsuarioActivo().getIdUsuario(), null, null, EstadoCita.PENDIENTE);
        if(c==null) {
            app.abrirPedirCita(Interfaces.PRINCIPAL_PACIENTE);
        } else {    // Solo puede tener una cita en pendiente
            app.abrirMensajeError("¡Ya tienes una cita pendiente!", Interfaces.PRINCIPAL_PACIENTE);
        }
    }

    @Action
    public void consultarCita() throws NoSuchAlgorithmException, IOException, ClassNotFoundException, SQLException {
        Cita [] c = Controlador.consultarCitas(Controlador.getUsuarioActivo().getIdUsuario(), null, null, EstadoCita.PENDIENTE);
        if(c==null) {
            app.abrirMensajeError("No se encontraron citas.", Interfaces.PRINCIPAL_PACIENTE);
        } else {    // Solo puede tener una cita en pendiente
            app.abrirVerCita(c[0]);
        }
    }

    @Action
    public void cancelarCita() throws SQLException, IOException, ClassNotFoundException, NoSuchAlgorithmException, ParseException {
        Cita [] c = Controlador.consultarCitas(Controlador.getUsuarioActivo().getIdUsuario(), null, null, EstadoCita.PENDIENTE);
        if(c==null) {
            app.abrirMensajeError("No se encontraron citas.", Interfaces.PRINCIPAL_PACIENTE);
        } else {    // Solo puede tener una cita en pendiente
            app.abrirCancelarCita(c[0]);
        }
        
    }

    @Action
    public void consultarEntregas() throws SQLException, IOException, ClassNotFoundException, ParseException {
        app.abrirVerEntregas(Controlador.getUsuarioActivo().getIdUsuario());
    }

    @Action
    public void consultarRecetas() throws SQLException, IOException, ClassNotFoundException, ParseException, NoSuchAlgorithmException {
        app.abrirVerRecetas(Controlador.getUsuarioActivo().getIdUsuario(),Interfaces.PRINCIPAL_PACIENTE);
    }





    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    // End of variables declaration//GEN-END:variables

}
